[illink] set $(StartupHookSupport)=false *only* for Release mode#10670
[illink] set $(StartupHookSupport)=false *only* for Release mode#10670jonathanpeppers merged 3 commits intomainfrom
$(StartupHookSupport)=false *only* for Release mode#10670Conversation
|
@rolfbjarne do you know if this works on iOS/Catalyst? |
tests/Mono.Android-Tests/Mono.Android-Tests/System/StartupHookTest.cs
Outdated
Show resolved
Hide resolved
startup hooks don't seem to work. Refs: * dotnet/android#10670 * https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md
I did a quick test, and it doesn't seem to work, so I filed an issue: dotnet/macios#24492 |
Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md .NET has a concept of a "startup hook", which appears to work fine on Mono if you set: env.txt DOTNET_STARTUP_HOOKS=StartupHook (MSBuild) <StartupHookSupport>true</StartupHookSupport> <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" /> The startup hook is a managed assembly with a static method, in the "global" namespace: class StartupHook { public static void Initialize() { // ... } } When the runtime starts, it will call `StartupHook.Initialize()` before any other managed code is executed. `dotnet watch` (Hot Reload) relies on this feature. I added a test to `Mono.Android-Tests` to verify that the startup hook was called. This is not yet working on CoreCLR on Android, investigation ongoing.
a09103f to
17176cd
Compare
| return; | ||
| } | ||
|
|
||
| var method = type.GetMethod (methodName, |
There was a problem hiding this comment.
Would it make sense to use the [UnsafeAccessor] attribute to avoid using reflection here?
There was a problem hiding this comment.
It looks like you can only do that if a type is public, and it's internal in System.Private.CoreLib.
| } | ||
|
|
||
| [RequiresUnreferencedCode ("Uses reflection to access System.StartupHookProvider.")] | ||
| static void RunStartupHooks () |
There was a problem hiding this comment.
Do you have a test to ensure this method is really trimmed away for a Release build (or when startuphook support is not enabled)?
There was a problem hiding this comment.
Yes, we run the new test in both trimmed, AOT, all runtimes, etc.
They have a line in dotnet/runtime to preserve it, too:
…10670) Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md .NET has a concept of a "startup hook", which appears to work fine on Mono if you set: env.txt DOTNET_STARTUP_HOOKS=StartupHook (MSBuild) <StartupHookSupport>true</StartupHookSupport> <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" /> The startup hook is a managed assembly with a static method, in the "global" namespace: class StartupHook { public static void Initialize() { // ... } } When the runtime starts, it will call `StartupHook.Initialize()` before any other managed code is executed. `dotnet watch` (Hot Reload) relies on this feature. I added tests to verify startup hooks are called on Android for all runtimes. * [coreclr] call `System.StartupHookProvider.ProcessStartupHooks()` This feature only works on CoreCLR if you have a `static void Main()`, which we do not on Android. For now, I called the `StartupHookProvider` directly with System.Reflection. We can address in dotnet/runtime in the future.
…10670) Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md .NET has a concept of a "startup hook", which appears to work fine on Mono if you set: env.txt DOTNET_STARTUP_HOOKS=StartupHook (MSBuild) <StartupHookSupport>true</StartupHookSupport> <RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="StartupHook" /> The startup hook is a managed assembly with a static method, in the "global" namespace: class StartupHook { public static void Initialize() { // ... } } When the runtime starts, it will call `StartupHook.Initialize()` before any other managed code is executed. `dotnet watch` (Hot Reload) relies on this feature. I added tests to verify startup hooks are called on Android for all runtimes. * [coreclr] call `System.StartupHookProvider.ProcessStartupHooks()` This feature only works on CoreCLR if you have a `static void Main()`, which we do not on Android. For now, I called the `StartupHookProvider` directly with System.Reflection. We can address in dotnet/runtime in the future.

Context: https://github.com/dotnet/runtime/blob/242f7b23752599f22157268de41fee91cb97ef6c/docs/design/features/host-startup-hook.md
.NET has a concept of a "startup hook", which appears to work fine
on Mono if you set:
The startup hook is a managed assembly with a static method, in the
"global" namespace:
When the runtime starts, it will call
StartupHook.Initialize()beforeany other managed code is executed.
dotnet watch(Hot Reload) relies on this feature.I added a test to
Mono.Android-Teststo verify that the startup hookwas called.
This is not yet working on CoreCLR on Android, investigation ongoing.